package leetcode.list;

public class Lc328 {


    public ListNode oddEvenList(ListNode head) {
        if (head == null) return head;
        ListNode ohead = new ListNode(), eHead = new ListNode();
        ListNode curNode = head, dummyEHead = eHead;
        boolean isOdd = true;
        while (curNode != null) {
            if (isOdd) {
                ohead.next = curNode;
                ohead = ohead.next;
                curNode = curNode.next;
                ohead.next = null;
                isOdd = !isOdd;
            } else {
                isOdd = !isOdd;
                eHead.next = curNode;
                eHead = eHead.next;
                curNode = curNode.next;
                eHead.next = null;

            }
        }
        ohead.next = dummyEHead.next;
        return head;
    }

}
